
use serde::{ Deserialize, Serialize };
use rbatis::rbdc::datetime::DateTime;


#[derive(Debug)]
#[derive(Clone)]
#[derive(lombok::Getter)]
#[derive(Serialize, Deserialize)]
pub struct User
{
    id: Option<u32>,
    avatar_id: Option<u32>,
    nickname: Option<String>,
    username: String,
    password: String,
    email: Option<String>,
    register_time: Option<DateTime>,
    last_login_time: Option<DateTime>
}
impl User
{
    pub fn new(nickname: String, username: String, password: String) -> Self
    {
        Self {
            id: Some(0),
            avatar_id: Some(1),
            nickname: Some(nickname),
            username,
            password,
            email: Option::None,
            register_time: Some(DateTime::now()),
            last_login_time: Option::None
        }
    }
}


rbatis::crud!(User{});//crud = insert+select_by_column+update_by_column+delete_by_column
rbatis::impl_select!(User{select_by_id(id:&str) -> Option => "`where id = #{id} limit 1`"});
rbatis::impl_select!(User{select_by_username(username:&str) -> Option => "`where username = #{username} limit 1`"});
rbatis::impl_update!(User{update_by_id(id:&str) => "`where id = #{id}"});
rbatis::impl_delete!(User {delete_by_id(id:&str) => "`where id = #{id}"});



